package com.googlecode.rjm.util;

import org.hibernate.Session;

public class HibernateUtil {
	
	private static Session currentSession;

	/**
	 * @return The Hibernate session being used currently, previously set by {@link #setCurrentSession(Session)}.
	 */
	public static Session getCurrentSession() {
		if (HibernateUtil.currentSession != null) {
			return HibernateUtil.currentSession;
		}
		throw new IllegalStateException("The current session is not set on HibernateUtil, please set it before invoke methods that need it.");
	}

	/**
	 * Set the Hibernate session being used currently, to be used by methods that need it.
	 * @param session
	 */
	public static void setCurrentSession(Session session) {
		HibernateUtil.currentSession = session;
	}

}
